home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !preview / c / buttons < prev    next >
Encoding:
Text File  |  1990-07-24  |  2.8 KB  |  107 lines

  1. /* buttons.c --- handle button changes and various.  */
  2.  
  3. #include "d2rd.h"
  4. #include "menus.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "kernel.h"
  9. #include "template.h"
  10. #include "resspr.h"
  11. #include "res.h"
  12.  
  13. struct display *which_menu;
  14.  
  15. wimp_menustr *iconbar_menu;
  16. menu window_menu, mag_menu, goto_page, saveas_menu;
  17.  
  18. char goto_page_buffer[12];
  19.  
  20. void
  21. handle_buttons (wimp_eventdata *b)
  22. {
  23.   struct display *w;
  24.   wimp_dragstr d;
  25.   wimp_icon ic;
  26.   wimp_mousestr m;
  27.   int i, x, y;
  28.  
  29.   /* Menu on the iconbar icon.  */
  30.  
  31.   if (b->but.m.bbits == wimp_BMID && b->but.m.w == -2 && b->but.m.i == iconbar_icon)
  32.     {
  33.       which_menu = 0;
  34.       wimp_create_menu (iconbar_menu, b->but.m.x - 64, 96 + 2 * 45);
  35.       return;
  36.     }
  37.  
  38.   /* Drag from the saveas menu-window.  */
  39.  
  40.   if (b->but.m.w == saveas && b->but.m.i == SAVEAS_FILEICON && b->but.m.bbits == wimp_BDRAGLEFT)
  41.     {
  42.       wimpt_noerr (wimp_get_point_info (&m));
  43.       wimpt_noerr (wimp_get_icon_info (saveas, SAVEAS_FILEICON, &ic));
  44.       d.window = saveas;
  45.       d.type = wimp_USER_FIXED;
  46.       x = ic.box.x1 - ic.box.x0;
  47.       y = ABS (ic.box.y1 - ic.box.y0);
  48.       d.box.x0 = m.x - x / 2;
  49.       d.box.y0 = m.y - y / 2;
  50.       d.box.x1 = m.x + x / 2;
  51.       d.box.y1 = m.y + y / 2;
  52.       d.parent.x0 = -4242;
  53.       d.parent.y0 = -4242;
  54.       d.parent.x1 = 4242;
  55.       d.parent.y1 = 4242;
  56.       wimpt_noerr (wimp_drag_box (&d));
  57.       return;
  58.     }
  59.  
  60.   /* OK clicked in the saveas menu leaf.  */
  61.  
  62.   if (b->but.m.w == saveas && b->but.m.i == SAVEAS_OKBUTTON)
  63.     {
  64.       if (strchr (saveas_buffer, '.'))
  65.         output_saveas (saveas_buffer);
  66.       else
  67.         fatal ("To save, drag icon to a directory viewer.");
  68.       return;
  69.     }
  70.  
  71.   for (w = windows; w; w = w->next)
  72.     if (w->w_handle == b->but.m.w)
  73.       break;
  74.  
  75.   wimp_get_point_info (&menu_pos);
  76.  
  77.   /* Sink a button event for an unknown window.  */
  78.  
  79.   if (w == NULL)
  80.     return;
  81.  
  82.   if (b->but.m.bbits == wimp_BMID)
  83.     {
  84.       /* Pop up the window menu.  Shade the `Next', `Previous' and `Goto
  85.          page' menu items in case the document only has one page.  */
  86.  
  87.       menu_setflags (window_menu, 1 + MAINMENU_NEXT, 0, w->page->next == NULL || w->page->next->complete == FALSE);
  88.       menu_setflags (window_menu, 1 + MAINMENU_PREVIOUS, 0, w->page == w->file->pages);
  89.       menu_setflags (window_menu, 1 + MAINMENU_GOTO_PAGE, 0, w->file->pages->next == NULL);
  90.  
  91.       /* Tick the approriate \magstep value.  */
  92.  
  93.       for (i = 0; i < 7; i++)
  94.         menu_setflags (mag_menu, 1 + i, w->magstep == i, 0);
  95.  
  96.       /* Tick the 75dpi tweak icon, if active */
  97.       menu_setflags (mag_menu, 8, w->mag_tweak != 1.0, 0);
  98.  
  99.       sprintf (goto_page_buffer, "%d", w->page->dvi_page);
  100.  
  101.       wimp_create_menu (menu_syshandle (window_menu), b->but.m.x - 64, b->but.m.y + 16);
  102.       which_menu = w;
  103.     }
  104. }
  105.  
  106. /* EOF buttons.c */
  107.